package {

   import flash.display.Sprite;
   import flash.events.*;
   import flash.net.*;
   
   import fm.last.*;
   import fm.last.api.*;
   import fm.last.error.*;

   public class Example1 extends Sprite {

      public function Example1() 
      {
         // example for artist.getSimilar http://www.last.fm/api/show?service=119
         var lastfm:LastFmService = new LastFmService(BaseTC._api_key);

         // get similar artistes of Cher
         // the `onComplete` callback function will be called then
         lastfm.artist.getSimilar(onComplete, onError, "cher");

         // this call will result in an error,
         // and the `onError` callback function will be called
         lastfm.artist.getSimilar(onComplete, onError, "No_Such_Artist");
      }
   
      /** parameter is an XML document */
      private function onComplete(response:XML):void 
      {
         // an successful response could be...
         /* <lfm status="ok">
          * <similarartists artist="Cher">
          *     <artist> 
          *        <name>Sonny &amp; Cher</name> 
          *        <mbid>3d6e4b6d-2700-458c-9722-9021965a8164</mbid> 
          *        <match>100</match> 
          *        <url>www.last.fm/music/Sonny%2B%2526%2BCher</url> 
          *        <image size="small">.....</image> 
          *     </artist> 
          *     <artist> 
          * ...
          * </similarartists>
          * </lfm>
          */

         // we can trace the mbid `3d6e4b6d-2700-458c-9722-9021965a8164`
         trace(response. similarartists.artist[0].mbid);
      }
 
      /** parameter is an ErrorEvent */
      private function onError(e:ErrorEvent):void 
      {
         trace(e.toString());
      }
   }
}